<template>
    <div class="wrapper">
        <div class="search">
            <div 
            class="search__back iconfont" 
            @click="handleBackClick"
            >
            &#xe681;
            </div>
            <div class="search__content">
                <span class="search__content__icon iconfont">&#xe648;</span>
                <input class="search__content__input" placeholder="请输入商品名称搜索"/>
            </div>
        </div>
        <ShopInfo :item="item" :hidBordered="true" v-show="item.imgUrl"/>
        <Content :shopName="item.name"/>
        <Cart/>
    </div>
</template>

<script>
import { reactive, toRefs } from 'vue'
import ShopInfo from '../../components/Shopinfo'
import Content from './Content.vue'
import Cart from './Cart.vue'
import { useRouter, useRoute} from 'vue-router'
import { get } from '../../utils/request'


//获取当前商铺信息
const  useShopInfoEffect=()=>{
    const route = useRoute()//route当前访问路径的信息
    const data = reactive({ item:{} })
    const getItemData= async () => {
        const result= await get(`/api/shop/${route.params.id}`)
        if(result?.errno===0 && result?.data){
            data.item=result.data
        }
    }
    const { item } = toRefs(data);
    return {item, getItemData}
}
//页面返回
const useBackRouterEffect=()=>{
    const router = useRouter();//router指的是当前整个大的路由信息
    const handleBackClick=()=>{
        router.back()
    }
    return {handleBackClick}
}
export default {
    name: 'Shop',
    components:{ ShopInfo, Content, Cart},
    setup() {
        const {item, getItemData}=useShopInfoEffect();
        getItemData();
        const {handleBackClick}=useBackRouterEffect();
        return { item, handleBackClick}
    }
}
</script>

<style lang="scss" scoped>
@import '../../style/viriables';
.wrapper{
    padding: .18rem .18rem 0 .18rem;
}
.search{
    display: flex;
    margin: .14rem 0 .04rem 0;
    line-height: .32rem;
    &__back{
        font-size: .24rem;
        width: .3rem;
        color: #B6B6B6;
    }
    &__content{
        display: flex;
        flex: 1;
        background: $search-bgcolor;
        border-radius: .16rem;
        &__icon{
            font-size: .24rem;
            width: .44rem;
            text-align: center;
            color: $search-fontcolor;
        }
        &__input{
            padding-right: .2rem;
            display: block;
            width: 100%;
            border: none;
            outline: none;
            background: none;
            height: .32rem;
            font-size: .14rem;
            color: $content-fontcolor;
            &::placeholder{
                color: $content-fontcolor;
            }
        }
    }
}
</style>